package com.jiutong.meipenggang.http.present;

import android.content.Context;

import com.jiutong.meipenggang.common.Constants;
import com.jiutong.meipenggang.entity.BaseBean;
import com.jiutong.meipenggang.entity.InvestMoneySuccessBean;
import com.jiutong.meipenggang.http.model.interfaces.InvestMoneySuccessBiz;
import com.jiutong.meipenggang.http.model.requests.MeiLiCaiFragmentRequest;
import com.jiutong.meipenggang.http.subscribers.ProgressSubscriber;
import com.jiutong.meipenggang.http.subscribers.SubscriberOnNextListener;
import com.jiutong.meipenggang.utils.SpConfig;
import com.jiutong.meipenggang.utils.TimeUitl;

import java.util.HashMap;

/**
 * @author Veken
 * @date on 2018/1/8 17:48
 * @describe
 */

public class InvestMoneySuccessPresent {
    private InvestMoneySuccessBiz investMoneySuccessBiz;
    private Context mContext;
    private MeiLiCaiFragmentRequest request;

    public InvestMoneySuccessPresent(Context mContext, InvestMoneySuccessBiz investMoneySuccessBiz) {
        this.mContext = mContext;
        this.investMoneySuccessBiz = investMoneySuccessBiz;
        request = new MeiLiCaiFragmentRequest();
    }

    /**
     * 获取美理财frament信息
     */
    public void investMoney(String bidId,String amount,String redId){
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<InvestMoneySuccessBean>() {
            @Override
            public void onNext(InvestMoneySuccessBean object) {
                investMoneySuccessBiz.investOnSuccess(object);
            }
            @Override
            public void onError(Throwable e) {
                investMoneySuccessBiz.onError(e);
            }
        };
        HashMap<String,Object> fieldMap = new HashMap<>();
        fieldMap.put("OPT",59);
        fieldMap.put("timestamp", TimeUitl.getDate());
        fieldMap.put("id", SpConfig.getInstance().getString(Constants.ID));
        fieldMap.put("token",SpConfig.getInstance().getString(Constants.TOKEN));
        fieldMap.put("bidId",bidId);
        fieldMap.put("amount",amount);
        fieldMap.put("redId",redId);
        request.investMoney(new ProgressSubscriber(onNextListener,mContext),fieldMap);
    }

}
